﻿<!DOCTYPE html>
<!--承包商入场人员名单编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <!-- 行内编辑 css-->
    <style>
        .tb-edit .el-input {
            display: none
        }

        .tb-edit .current-row .el-input {
            display: block
        }

        .tb-edit .current-row .el-input+span {
            display: none
        }

        .tb-edit .el-date-editor {
            display: none
        }

        .tb-edit .current-row .el-date-editor {
            display: block
        }

        .tb-edit .current-row .el-date-editor+span {
            display: none
        }

        .xian {
            display: block;
            text-align: center;
        }

        .yin {
            display: none;
            text-align: center;
        }

        .lineMust {
            position: absolute;
            right: 15px;
            bottom: 6px;
            bottom: 3px\0 !important;
            /* 兼容ie */
        }

        .tb-edit .el-date-editor {
            width: 100% !important;
        }
        .el-input__suffix {
            width: 100% !important;
        }
    </style>
    <!-- 行内编辑 css-->
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ContractorAdmissionList.ContractorName+mark.m}}
                                </template>
                                <el-select @visible-change="visibleChange" v-model="CBSListId" slot="suffix"  @change="postChange" style="margin-left: 150px;">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in CBS_Lists" :label="item.contractorName"
                                               :value="item.id"></el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <!-- <el-col :span="11" :offset="2">
        <div class="elst-select-mini">
            <el-form-item :label="ContractorAdmissionList.AdmissionName+mark.m" prop="AdmissionName"
                class="inputTextarea">
                <treeselect v-model="Form.AdmissionName" :multiple="true" :options="AdmissionName"
                    :flat="true" :show-count="true" :disable-branch-nodes="true" placeholder="请选择" />
            </el-form-item>
        </div>
    </el-col> -->
                <!-- <el-col :span="11" :offset="2">
        <div class="elst-select-mini">
            <el-form-item>
                <el-input type="text" v-model="Form.AdmissionName" autocomplete="off" size="mini">
                    <template slot="prepend">
                        {{ContractorAdmissionList.AdmissionName+mark.m}}
                    </template>
                </el-input>
            </el-form-item>
        </div>
    </el-col> -->

                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ContractorAdmissionList.Region+mark.m}}
                                </template>
                                <treeselect v-model="Form.region" :options="TreeData" :flat="true"
                                            slot="suffix" placeholder="请选择区域"
                                            style="line-height: 28px;margin-left: 150px;" />
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11">
                    <el-form-item>
                        <div class="elst-select-mini">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ContractorAdmissionList.AdmissionTime+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.admissionTime" type="datetime" style="margin-left: 150px;"
                                                size="mini" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
                                                placeholder="选择时间">
                                </el-date-picker>

                            </el-input>
                        </div>
                    </el-form-item>
                </el-col>
                <!-- <el-col :span="11">
        <div class="elst-select-mini">
            <el-form-item>
                <el-input type="text" v-model="Form.AdmissionConfirmer" autocomplete="off" size="mini"
                    :disabled="true">
                    <template slot="prepend">
                        {{ContractorAdmissionList.AdmissionConfirmer+mark.m}}
                    </template>
                </el-input>
            </el-form-item>
        </div>
    </el-col>
    <el-col :span="11" :offset="2">
        <el-form-item :label="ContractorAdmissionList.FactoryTime+mark.m" prop="CertificateValidity">
            <el-date-picker v-model="Form.FactoryTime" type="datetime" placeholder="选择日期时间">
            </el-date-picker>
        </el-form-item>
    </el-col>-->

            </el-row>
            <!--<el-row>
                 <el-col :span="11">
                     <div class="elst-select-mini">
                         <el-form-item>
                             <el-input type="text" v-model="Form.FactoryConfirmer" autocomplete="off" size="mini" >
                                 <template slot="prepend">
                                     {{ContractorAdmissionList.FactoryConfirmer+mark.m}}
                                 </template>
                             </el-input>
                         </el-form-item>
                     </div>
                 </el-col>
             </el-row>-->


            <el-row>
                <el-col class="head-tool">
                    <el-button type="primary" @click="add" size="mini">增加人员</el-button>
                </el-col>
            </el-row>
            <!--表格开始-->
            <el-table ref="table" stripe @current-change="tableHandleCurrentChange" class="tb-edit"
                      :data="Form.PeopleList" :row-key="getRowKeys" border @selection-change="handleSelectionChange"
                      row-style="height:10px" style="width: 100%;">

                <el-table-column prop="cbsUserId" :label="ContractorAdmissionList.AdmissionName"
                                 show-overflow-tooltip="true">
                    <template scope="scope">
                        <el-input size="mini">
                            <el-select @visible-change="visibleChange" v-model="scope.row.cbsUserId" slot="suffix">
                                <el-option label="请选择" value=""></el-option>
                                <el-option v-for="item in CBS_UserLists" :label="item.personnelName"
                                           :value="item.personnelName"></el-option>
                            </el-select>
                        </el-input>
                        <span>{{scope.row.cbsUserId}}</span>

                        <span class="lineMust">
                            <!-- 必填项添加 -->
                            <img src="/static/images/exclamation.png" alt="">
                        </span>
                    </template>
                </el-table-column>
                <el-table-column prop="endTime" :label="ContractorAdmissionList.CertificateValidity"
                                 show-overflow-tooltip="true">
                    <template scope="scope">
                        <el-date-picker v-model="scope.row.endTime" format="yyyy-MM-dd"
                                        value-format="yyyy-MM-dd" type="date" slot="suffix" size="mini" placeholder="选择日期">
                        </el-date-picker>
                        <span>{{scope.row.endTime}}</span>

                        <span class="lineMust">
                            <!-- 必填项添加 -->
                            <img src="/static/images/exclamation.png" alt="">
                        </span>
                    </template>
                </el-table-column>



                <el-table-column width="90" prop="update" label="编辑">
                    <template slot-scope="scope">
                        <span class="start xian">
                            <button type="button" class="elst-bt-xg" @click=Edit('xg',scope.row.id,scope.$index)>
                                <i class="el-icon-edit"></i>
                            </button>
                        </span>
                        <span class="end yin">
                            <button type="button" class="elst-bt-xg " @click="Save(scope.$index, scope.row)">
                                <i class="el-icon-circle-check-outline"></i>
                                <!-- 保存 -->
                            </button>
                            <!--<button type="button" @click.native.prevent="deleteRow(scope.$index, Form.PeopleList)">-->
                            <button type="button" class="elst-bt-xg " @click="Back(scope.$index, scope.row)">
                                <i class="el-icon-circle-close-outline"></i>
                                <!-- 撤销 -->
                            </button>
                        </span>
                    </template>
                </el-table-column>
                <el-table-column width="90" label="操作" align="center">
                    <template slot-scope="scope">
                        <button type="button" class="elst-bt-xg" @click="deleteRow(scope.$index, Form.PeopleList)">
                            <i class="el-icon-delete"></i>
                        </button>
                    </template>
                </el-table-column>
                <el-table-column prop="id" width="1"  :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <span>{{scope.row.id}}</span>
                    </template>
                </el-table-column>
            </el-table>
            <br>
            <div class="fr">
                <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>-->
                <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                <el-button type="primary" @click="onBack">{{col.btnBack}}</el-button>
            </div>
        </el-form>
        <el-dialog :title="title" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%" height="80%"
            top="0vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:280px;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                title: '',
                //mydata: PersonInChargeTree,
                //区域
                TreeData: [],
                CBS_Lists: [],
                CBS_UserLists: [],
                CBSListId: null,
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    AdmissionName: '',
                    region: null,
                    CertificateValidity: '',
                    ContractorName: '',
                    FactoryTime: '',
                    AdmissionConfirmer: '',
                    FactoryConfirmer: '',
                    CreateFactory:'',
                    AdmissionName: null,
                    PeopleList: []
                },
                AdmissionName: [],
                ListItem: ListItem,
                //表单验证
                rules: {
                    AdmissionName: [
                        verification.NotNull,
                    ],
                    ContractorName: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(5, 50), message: verification.StringLengthAtoB.m.format(5, 10), trigger: 'blur' }
                    ],
                    region: [
                        verification.NotNullSelect
                    ],
                    CertificateValidity: [
                        verification.NotNull
                    ]
                }
            },

            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                // 行内编辑 js
                add: function (formName) {
                    //if (this.formInline.model.classification == undefined) {
                    //    showMessage('必须选择评估类型!', 'error'); return;
                    //}
                    //alert('xxxxxxx');
                    if ($('tbody tr').attr("class") == "el-table__row current-row") {
                        showMessage(msg.EditingNotCompleted, 'error');
                    } else {

                        //this.lsForm.department = '';//添加是清空录入数据的，每一项都要有
                        //this.lsForm.evaluator = '';//添加是清空录入数据的，每一项都要有
                        //this.lsForm.post = '';//添加是清空录入数据的，每一项都要有
                        //this.lsForm.straightLine = '';//添加是清空录入数据的，每一项都要有
                        //this.lsForm.remarks = '';//添加是清空录入数据的，每一项都要有

                        //this.Form.department = '';//添加是清空录入数据的，每一项都要有
                        //this.Form.evaluator = '';//添加是清空录入数据的，每一项都要有
                        //this.Form.post = '';//添加是清空录入数据的，每一项都要有
                        //this.Form.straightline = '';//添加是清空录入数据的，每一项都要有
                        //this.Form.remarks = '';//添加是清空录入数据的，每一项都要有


                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');

                        //if (!this.Form.PeopleList) {
                        //    this.Form.PeopleList = [];
                        //}


                        var newObj = {
                            cbsUserId: '',//添加是清空录入数据的，每一项都要有
                            endTime: '',//添加是清空录入数据的，每一项都要有
                        }
                        this.Form.PeopleList.unshift(newObj);
                        //this.Form.PeopleList.unshift(this.Form);

                        //console.log("abegf", this.Form.PeopleList);
                        setTimeout(function () {
                            $('.el-table__row:eq(0)').addClass('current-row');
                            $('.el-table__row:eq(0) span.end').removeClass('yin');
                            $('.el-table__row:eq(0) span.end').addClass('xian');
                            $('.el-table__row:eq(0) span.start').removeClass('xian');
                            $('.el-table__row:eq(0) span.start').addClass('yin');
                        }, 100);
                    }
                },
                //修改
                Edit: function (val, id, index) {
                    $('.el-table__row').removeClass('current-row');
                    $('.el-table__row:eq(' + index + ')').addClass('current-row');
                    $('.el-table__row span.end').removeClass('xian');
                    $('.el-table__row span.end').addClass('yin');
                    $('.el-table__row span.start').removeClass('yin');
                    $('.el-table__row span.start').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.end').removeClass('yin');
                    $('.el-table__row:eq(' + index + ') span.end').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').removeClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').addClass('yin');
                },
                // 保存 注意去掉mock中的parent 否则无法保存
                Save: function (a, b) {
                    if (!b.cbsUserId || !b.endTime) {
                        showMessage(msg.NoMust, 'error');
                    }
                    //else if (!this.check(b.score)) {
                    //    showMessage('赋值分数必须为正整数!', 'error');
                    //}
                    else {
                        // this.onSubmitForm('ruleForm', b);
                        //this.onSubmitForm('form', b);


                        //var newObj = {};
                        //$.extend(true, newObj, this.lsForm);

                        //console.log('newObj', newObj)
                        // this.Form.PeopleList.unshift(newObj);





                        $('.el-table__row').removeClass('current-row');
                        //console.log("a", a);
                        //console.log("b", b);
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');
                        //初始化数据
                        // this.GetPageData(1);
                    }
                },
                Back: function (a, b) {
                    $('.el-table__row').removeClass('current-row');
                    $('.el-table__row span.end').removeClass('xian');
                    $('.el-table__row span.end').addClass('yin');
                    $('.el-table__row span.start').removeClass('yin');
                    $('.el-table__row span.start').addClass('xian');
                    //初始化数据
                    // this.GetPageData(1);
                    this.getData();
                },

                handblur: function () {
                    //this.$refs.table.setCurrentRow(999);
                    //console.log("c", 'c');
                },
                //table选中行handle
                tableHandleCurrentChange: function (currentRow) {
                    this.currSeelctId = currentRow.id;
                    this.currSeelctCell = currentRow;
                },
                //删除列表行
                deleteRow: function (index, rows) {
                    var mythis = this; if (mythis.Form.PeopleList[index].id == null || mythis.Form.PeopleList[index].id == "" || mythis.Form.PeopleList[index].id == undefined) {
                        rows.splice(index, 1);
                    } else {
                        myAjax("post", mythis, '/api/CBS_IntoFactoryUser/DeleteMuti', [mythis.Form.PeopleList[index].id], function (response) {
                            rows.splice(index, 1);
                        });
                    }
                    
                },
                // 行内编辑 js
                indexMethod: function (index) {
                    return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1;
                },


                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            for (var i = 0; i < mythis.Form.PeopleList.length; i++) {
                                //mythis.Form.PeopleList[i].id = mythis.Form.CBSListId;
                                for (var j = 0; j < mythis.CBS_UserLists.length; j++) {
                                    if (mythis.CBS_UserLists[j].personnelName == mythis.Form.PeopleList[i].cbsUserId) {
                                       
                                        mythis.Form.PeopleList[i].cbsUserId = mythis.CBS_UserLists[j].id;
                                       
                                    }
                                }
                                mythis.Form.PeopleList[i].CBSListId = mythis.CBSListId;
                                mythis.Form.PeopleList[i].Region = mythis.Form.region;
                                mythis.Form.PeopleList[i].AdmissionTime = mythis.Form.admissionTime;
                                onSubmitForm(this, '/api/CBS_IntoFactoryUser/Save', mythis.Form.PeopleList[i]);
                            }
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                   
                    var mythis = this;
                    if (mythis.id != null && mythis.id != '') {
                        myAjax("get", mythis, '/api/CBS_IntoFactoryUser/get?id=' + this.id, null, function (response) {
                            var ajaxModel = response.data;
                            mythis.Form = ajaxModel;
                            mythis.CBSListId = ajaxModel.cbsListId;
                            myAjax("post", this, '/api/CBS_User/GetList', { model: { status: '', CreateFactory: null, CBSListId: mythis.CBSListId }, offset: 0, limit: 100 }, function (response) {
                                mythis.CBS_UserLists = response.data.pageData;
                                //console.log('h1', response.data.pageData);
                                myAjax("post", this, '/api/CBS_IntoFactoryUser/GetList', { model: { cbsListId: ajaxModel.cbsListId, region: ajaxModel.region, admissionTime: ajaxModel.admissionTime, admissionConfirmer: ajaxModel.admissionConfirmer }, offset: 0, limit: 100 }, function (response) {
                                    var PeopleList = response.data.pageData;
                                    for (var i = 0; i < PeopleList.length; i++) {
                                        for (var j = 0; j < mythis.CBS_UserLists.length; j++) {
                                            if (mythis.CBS_UserLists[j].id == PeopleList[i].cbsUserId) {

                                                PeopleList[i].cbsUserId = mythis.CBS_UserLists[j].personnelName;

                                            }
                                        }
                                    }
                                    mythis.Form.PeopleList = PeopleList;
                                    //console.log('h1', response.data.pageData);
                                }, false);
                            }, false);

                           
                            //mythis.userFrom.sex = mythis.userFrom.sex + "";
                        }, false);
                    }
                },
                onBack: function () {
                    parent.app.ListItem.dialogVisible = false;
                },
                //初始化承包商下拉框
                getCBS_List: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/CBS_List/GetList', { model: { status: '', CreateFactory: null }, offset: 0, limit: 100 }, function (response) {
                        mythis.CBS_Lists = response.data.pageData;
                        //console.log('h1', response.data.pageData);
                    }, false);
                },
                //初始化承包商人员下拉框
                getCBS_UserList: function () {
                    var mythis = this;
                    if (mythis.CBSListId == null || mythis.CBSListId == "" || mythis.CBSListId == undefined) { } else {
                        myAjax("post", this, '/api/CBS_User/GetList', { model: { status: '', CreateFactory: null, CBSListId: this.CBSListId }, offset: 0, limit: 100 }, function (response) {
                            mythis.CBS_UserLists = response.data.pageData;
                            //console.log('h1', response.data.pageData);
                        }, false);
                    }
                },
                postChange: function (val) {
                    //初始化承包商选项
                    if (this.id == null) {
                        this.CBS_UserLists = [];
                    }
                    this.CBSListId = val;
                    //获取承包商下人员
                    this.getCBS_UserList();
                }
            },
            mounted: function () {
                //this.AdmissionName = fn(this.mydata, "0");
                this.TreeData = GetAreaTreeData(this, this.Form.CreateFactory);
                this.id = getUrlParam("id");
                this.getCBS_List();
                this.getData();
            }
        });
        function MenuHelper(list, pid) {
            var result = [];

            list.forEach(function (v, i) {
                if (!v.parentId) v.parentId = guidEmpty;
                if (v.parentId == pid) {
                    var obj = v;
                    obj.id = obj.id + '';
                    obj.label = obj.name + '';
                    obj.icon = 'tree-item';
                    var nextObj = MenuHelper(list, v.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                        obj.icon = 'tree-open';
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>